#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 7;
int m, n, L, V, ans, cnt, stt, en, mx;
int a[N], d[N], v[N], p[N];
bool tt, ee;

int main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int T;
    cin >> T;
    while (T--){
        tt = ee = false;
        cin >> n >> m >> L >> V;
        ans = cnt = mx = 0;
//        memset(vis, 0, sizeof(vis));
//       memset(b, 0, sizeof(b));
//        memset(mrk, 0, sizeof(mrk));
        for (int i = 1; i <= n; i++) { cin >> d[i] >> v[i] >> a[i]; if (a[i] < 0) tt = true; if (a[i] > 0) ee = true;}
        for (int i = 1; i <= m; i++) {
            int x;
            cin >> x;
             p[x] = 1;
             mx = max(mx, x);
        }
        if (tt == false && ee == false){
            for (int i = 1; i <= n; i++){
                if(v[i] > V && d[i] <= mx) {
                    ans++;
                }
            }
            if (ans == 0) cout << "0 " << m << '\n';
            else cout << ans << " " << (m-1) << '\n';
            continue;
        }
        if (tt == false && ee == true){
            for (int i = 1; i <= n; i++){
                if (v[i]*v[i] + 2*a[i]*(mx-d[i]) > V*V && d[i] <= mx) ans++;
            }
            if (ans == 0) cout << "0 " << m << '\n';
            else cout << ans << " " << (m-1) << '\n';
            continue;
        }
        /*
        for (int i = 1 ;i <= n; i++){
            stt = en = 0;
            if (a[i] > 0){
                for (int j = d[i]; j <= mx; j++){
                    if (p[j] == 0) continue;
                    if (v[i]*v[i] + 2*a[i]*(j-d[i]) > V*V){
                        ans++;
                        vis[mx] = max(vis[mx], j);
                        break;
                    }
                }
            }

            else if (a[i] == 0) {
                if(v[i] > V && d[i] <= mx) {
                    ans++;
                    for (int j = d[i]; j <= mx; j++) if (p[j]) vis[mx] = max(vis[mx], j);
                }
            }
            //a[i] < 0
            else {
                for (int j = d[i]; j <= mx; j++){
                    if (p[j] == 0) continue;
                    if (v[i]*v[i] + 2*a[i]*(j-d[i]) <= V*V) break;
                    if (mrk[i] == 0){
                        ans++;
                        mrk[i] = 1;
                        stt = j;
                    }
                    en = j;
                }
                vis[en] = max(vis[en], stt);
            }
        }

        for (int i = 1; i <= mx; i++) b[vis[i]] = i;
        for (int i = 1; i <= mx; i++){
            int j = 1;
            if (vis[i] == 0) continue;
            for (; j <= i; j++) vis[b[j]] = 0;
            cnt++;
        }
        cout << ans << " " << (m-cnt) << '\n';
        */
    }
    return 0;
}
/*
9 10 114934 719
62115 915 -6
44976 920 -17
21788 877 -1
38609 839 -3
44828 982 -8
9713 1000 -109
61421 860 -922
16064 918 -2
33522 989 -11
13230 19868 37544 44774 45209 54175 61486 62595 87581 101248
*/

